﻿var dataType = 4;
var queryParam = {};
var datetype=2;
var systemType = -1;
var logManagement = {
	init : function() {
	    //初始化按钮
        setMenuButtonOpermission();
	    
	    systemType = getUrlParam("systemType");
		
		//$("#txtStartTime").datebox("setValue", curDay);
		//$("#txtEndTime").datebox("setValue", curDay);	
		$('#searchlogType').combobox({
			url : getProjectUrl('/bfs/configuration/categorylist?type=0&categoryclass=logType'),
			valueField : 'generalCode',
			textField : 'categoryName',
			onLoadSuccess : function() { // 加载完成后,设置选中第一项
				$(this).combobox('select', "");
			}
		});
		initDateTypeCtrl("dateTypeCtrl",datetype,1);
		var d = new Date();
		var curDay = d.format("yyyy-MM-dd"); 
		$("#endTime").val(curDay);
		$('.form_date').datetimepicker('setEndDate', curDay);
		logManagement.loadData();
	},
	validateInput : function() {
		
		queryParam=getDateTypeQueryParam(datetype);
		queryParam.logContent = $('#logContent').val();
		queryParam.logType = $('#searchlogType').combobox('getValue');
		queryParam.systemType = systemType;
		queryParam.logTime = queryParam.startTime;
	},
	loadData : function() {
		$(".list").show();
		$(".nolist").hide();
		logManagement.validateInput();
		if (queryParam.valid) {
			var dataUrl = getProjectUrl("/bfs/configuration/systemlog");
			var dataParams = {
				logTime : queryParam.startTime,
				endTime : queryParam.endTime,
				// systemType : queryParam.systemType,
				logContent : queryParam.logContent,
				logType : queryParam.logType,
				// logTime:queryParam.logTime
			};
			$('#listDataEx1').datagrid({
				url : dataUrl,
				rows : true,
				queryParams : dataParams,
				fit : true,
				fitColumns : true,
				rownumbers : true,  
				autoRowHeight : true,
				nowrap : false,
				pagination : true,
				pageSize : 20,
				pageList : [ 20, 50, 100, 200 ],
				// 当监测点的名称相同的时候，合并单元格
				onLoadSuccess : function(data) {
				    setMenuButtonOpermission();
				    $(this).datagrid("fixRownumber");
				    if(data.rows === null || data.rows.length === 0){
						   $(".list").hide();
						   $(".nolist").css("height", $(".list").outerHeight()).show();	 
					}
				},
				columns : [ [ {
					field : 'logType',
					title : '日志类型',
					width : 10,
					styler : function(value, row, index) {
						return 'vertical-align:middle';
					}
				},  {
					field : 'logContent',
					title : '日志内容',
					width : 45,
					styler : function(value, row, index) {
						return 'vertical-align:middle;';
					},
				}, {
					field : 'logTime',
					title : '操作时间',
					width : 17,
					styler : function(value, row, index) {
						return 'vertical-align:middle';
					}
				}, {
					field : 'userName',
					title : '用户名',
					width : 10,
					styler : function(value, row, index) {
						return 'vertical-align:middle';
					},
				}, {
					field : 'operatorIp',
					title : '操作IP',
					width : 15,
					styler : function(value, row, index) {
						return 'vertical-align:middle';
					}
				} ] ]
			});
		}
	}
};

$(document).ready(function() {
	resetSize();
	logManagement.init();
});